package snafu.framework.states.literals;

import snafu.framework.view.Access;
import snafu.framework.view.ViewFactory;

public abstract class StateLiteralItself<T> implements StateLiteral<T>, ViewFactory<StateLiteralView<T>> {

	/** The value. */
	protected T value;
	/** The access type. */
	protected Access privacy;
	
	/**
	 * Instantiates a new state literal with the given value.
	 * 
	 * @param value
	 *            the value attached to this litera
	 * @param privacy
	 *            the access type
	 */
	public StateLiteralItself(T value, Access privacy) {
		this.value = value;
		this.privacy = privacy;
	}
	
	@Override
	public T getValue() {
		return value;
	}
	
	/**
	 * Sets the value of this literal.
	 * 
	 * @param value
	 *            the value to set
	 */
	public void setValue(T value) {
		this.value = value;
	}
	
	/**
	 * Returns the access type
	 * 
	 * @return the access type
	 */
	public Access getPrivacy() {
		return privacy;
	}
	
	@Override
	public boolean equals(Object o) {
		if (!(o instanceof StateLiteral<?>))
			return false;
		
		Class<?>[] interfaces = this.getClass().getInterfaces();
		
		for (Class<?> clazz : interfaces) {
			if (clazz.isAssignableFrom(o.getClass()) && clazz.isAssignableFrom(this.getClass())
					&& StateLiteral.class.isAssignableFrom(clazz))
				return true;
		}
		
		return false;
	}
	
}
